Skip to content

upgrade to zig 0.16.0#30

Merged
hazeycode merged 1 commit into
zig-gamedev:mainfrom
MokaHiko:chore/update-to-zig-0.16.0
Apr 22, 2026
Merged

upgrade to zig 0.16.0#30
hazeycode merged 1 commit into
zig-gamedev:mainfrom
MokaHiko:chore/update-to-zig-0.16.0

Conversation

@MokaHiko
Copy link
Copy Markdown
Contributor

  • Replace std.time.Timer.start()/.read() to std.Io.Clock.now() and .durationTo() in benchmark.zig, threading pass io context from "juicy main" std.process.Init
  • Fix ArrayList.deinit() calls to pass allocator explicitly
  • Fix vector element access with runtime index (ie % 4) by casting to [4]f32 array first, as Zig now requires comptime-known indices for vector types
  • Fix min/max to manually implement DirectX-style NaN semantics using @select, since @min/@max NaN propagation behavior changed

@MokaHiko MokaHiko mentioned this pull request Apr 22, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the project to be compatible with Zig 0.16.0 by adapting timing/IO APIs, allocator-aware deinit calls, vector indexing rules, and NaN semantics changes in min/max.

Changes:

  • Bump minimum Zig version to 0.16.0.
  • Refactor benchmarks to use std.process.Init + std.Io.Clock and allocator-aware ArrayList.deinit.
  • Update min/max NaN behavior and fix vector runtime indexing in FFT tests.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/root.zig Adjusts min/max NaN semantics and fixes runtime vector element access in FFT tests.
src/benchmark.zig Migrates benchmarks to Zig 0.16 “juicy main” init + std.Io.Clock, and updates ArrayList.deinit signatures.
build.zig.zon Raises .minimum_zig_version to 0.16.0.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/root.zig
Comment on lines +791 to +798
const Child = std.meta.Child(T);
// v != v is true only when v is NaN
const nan0 = v0 != v0;
const nan1 = v1 != v1;
// if v0 is NaN, pick v1
// else if v1 is NaN, pick v0
// else pick normal @min
return @select(Child, nan0, v1, @select(Child, nan1, v0, @min(v0, v1)));
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std.meta.Child(T) will fail to compile when T is a scalar type (e.g. f32, i32), even though this function’s anytype signature previously allowed scalar @min usage. Consider deriving the element type only for vectors (e.g. via @typeInfo(T)), and otherwise using T itself as the @select type parameter so scalar callers still compile.

Suggested change
const Child = std.meta.Child(T);
// v != v is true only when v is NaN
const nan0 = v0 != v0;
const nan1 = v1 != v1;
// if v0 is NaN, pick v1
// else if v1 is NaN, pick v0
// else pick normal @min
return @select(Child, nan0, v1, @select(Child, nan1, v0, @min(v0, v1)));
const SelectT = switch (@typeInfo(T)) {
.Vector => |info| info.child,
else => T,
};
// v != v is true only when v is NaN
const nan0 = v0 != v0;
const nan1 = v1 != v1;
// if v0 is NaN, pick v1
// else if v1 is NaN, pick v0
// else pick normal @min
return @select(SelectT, nan0, v1, @select(SelectT, nan1, v0, @min(v0, v1)));

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think supporting scalar types here is actually important.

Comment thread src/root.zig
Comment on lines +841 to +843
const T = @TypeOf(v0, v1);
const Child = std.meta.Child(T);
// v != v is true only when v is NaN
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as min: using std.meta.Child(T) will not compile for scalar T, turning max into a vector-only API despite its generic signature. Use a conditional element-type derivation for vectors and fall back to T for scalar types when calling @select.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

@hazeycode hazeycode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@hazeycode hazeycode merged commit eec8bca into zig-gamedev:main Apr 22, 2026
7 checks passed
@MokaHiko MokaHiko deleted the chore/update-to-zig-0.16.0 branch April 23, 2026 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants